package v1

import (
	"github.com/gin-gonic/gin"
	"guns-go/model/request"
	"guns-go/model/response"
	"guns-go/service"
)

// @Tags Config
// @Summary 分页获取配置管理列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysConfigParam true "请求参数"
// @Success 200 {string} string "{"success":true,"data":{},"message":"请求成功","code":200}"
// @Router /sysConfig/page [get]
func SysConfigPage(c *gin.Context) {

	var Config request.SysConfigParam
	_ = c.ShouldBindQuery(&Config)

	err, SysConfigPageResult := service.SysConfigPage(&Config, c)

	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.OkWithData(SysConfigPageResult, c)
}

// @Tags Config
// @Summary 新增配置管理
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysConfigParam true "请求参数"
// @Success 200 {string} string "{"success":true,"data":{},"message":"请求成功","code":200}"
// @Router /sysConfig/add [post]
func SysConfigAdd(c *gin.Context) {

	var Config request.SysConfigParam
	_ = c.ShouldBindJSON(&Config)

	err := service.SysConfigAdd(&Config)

	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.Ok(c)
}

// @Tags Config
// @Summary 修改配置管理
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysConfigParam true "请求参数"
// @Success 200 {string} string "{"success":true,"data":{},"message":"请求成功","code":200}"
// @Router /sysConfig/edit [post]
func SysConfigEdit(c *gin.Context) {

	var Config request.SysConfigParam
	_ = c.ShouldBindJSON(&Config)

	err := service.SysConfigEdit(&Config)

	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.Ok(c)
}

// @Tags Config
// @Summary 删除配置管理
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysConfigParam true "请求参数"
// @Success 200 {string} string "{"success":true,"data":{},"message":"请求成功","code":200}"
// @Router /sysConfig/delete [post]
func SysConfigDelete(c *gin.Context) {

	var Config request.SysConfigParam
	_ = c.ShouldBindJSON(&Config)

	err := service.SysConfigDelete(&Config)

	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.Ok(c)
}
